package com.doushu.websocket.controller;

import com.doushu.websocket.common.dto.ResultDto;
import com.doushu.websocket.service.MsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;

@RestController
@Api(description = "消息controller")
public class MsgController {

    @Autowired
    private MsgService msgService;

    @RequestMapping(value = "/push", method = RequestMethod.POST)
    @ApiOperation(value = "推送消息给指定店铺插件", httpMethod = "POST")
    public ResultDto push(
            @ApiParam(name = "shopId",value="店铺id",required = true)@RequestParam String shopId,
            @ApiParam(name = "token",value="登录的token")@RequestParam(required = false) String token,
            @ApiParam(name = "type",value="消息类型",required = true)@RequestParam String type,
            @ApiParam(name = "msg",value="消息",required = true)@RequestParam String msg) {
        return msgService.push(shopId, token, type, msg);
    }

    @RequestMapping(value = "/pushAll", method = RequestMethod.POST)
    @ApiOperation(value = "推送消息给所有插件", httpMethod = "POST")
    public ResultDto pushAll(
            @ApiParam(name = "msg",value="消息",required = true)@RequestParam String msg){
        return msgService.pushAll(msg);
    }

    @RequestMapping(value = "/allUserKey", method = RequestMethod.POST)
    @ApiOperation(value = "获取所有用户Key", httpMethod = "POST")
    public ResultDto allUserKey(){
        return msgService.allUserKey();
    }
}
